<template>
  <div id="shareTopSearch">
    <h1 class="con-right-title">
      直播间主播个人数据
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="parameter"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-row>
          <el-form-item label="用户搜索" prop="dpAccount">
            <el-input
              
              v-model="parameter.dpAccount"
              placeholder="请输入大鹏号"
              size="small"
              class="numberInput"
            ></el-input>
          </el-form-item>
          <el-form-item class="s-btn">
            <el-button
              type="success"
              icon="el-icon-search"
              @click="toSearch('ruleForm')"
            >
              查询
            </el-button>
            <el-button type="success" plain @click="reset">
              重置
            </el-button>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="总开播时长" prop="duration.orderType">
            <el-select v-model="parameter.duration.orderType" @change="e => {checkValue(e,'DURATION')}" placeholder="请选择" >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="总观看人数" prop="watch_count_nv.orderType">
            <el-select v-model="parameter.watch_count_nv.orderType" @change="e => {checkValue(e,'WATCH_COUNT_UV')}" placeholder="请选择" >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="总获赞数量" prop="like_count.orderType">
            <el-select v-model="parameter.like_count.orderType" @change="e => {checkValue(e,'LIKE_COUNT')}" placeholder="请选择" >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="总收获礼物数" prop="gift_count.orderType">
            <el-select v-model="parameter.gift_count.orderType" @change="e => {checkValue(e,'GIFT_COUNT')}" placeholder="请选择" >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <add-dialog
      v-if="dialogVisible"
      @changeVisible="changeVisible"
      :dialogVisible="dialogVisible"
    ></add-dialog>
  </div>
</template>

<script>
// import AddDialog from './addDialog'
export default {
  name: 'shareTopSearch',
  msg: '主播列表管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          dpAccount: '', // 大鹏号
          orderType: '', // 排序类型
          sortField: '', // 排序字段
        }
      }
    },
    streamStatus: {
      type: Array
    }
  },
  components: {
    // AddDialog
  },
  data() {
    return {
      parameter:{
        dpAccount:'',
        duration:{// 开播时长
          sortField:'DURATION',
          orderType:'DESC'
        },
        watch_count_nv:{// 观看人数
          sortField:'',
          orderType:''
        },
        like_count:{// 获赞数量
          sortField:'',
          orderType:''
        },
        gift_count:{// 礼物数
          sortField:'',
          orderType:''
        },
      },
      options: [
       {label:'请选择',value:''},
       {label:'从多到少排序',value:'DESC'},
       {label:'从少到多排序',value:'ASC'},
      ],
      // 学院列表
      rules: {
       dpAccount:{},
       'duration.orderType':{},
       'watch_count_nv.orderType':{},
       'like_count.orderType':{},
       'gift_count.orderType':{}
      },
      dialogVisible: false
    }
  },
  methods: {
    checkValue(value,e){
      const self = this
      this.formInline.orderType = value
      this.formInline.sortField = e
      switch (e) {
        case 'DURATION':
          self.parameter.watch_count_nv.orderType = ''
          self.parameter.like_count.orderType = ''
          self.parameter.gift_count.orderType = ''
          break;
        case 'WATCH_COUNT_UV':
            self.parameter.duration.orderType = ''
            self.parameter.like_count.orderType = ''
            self.parameter.gift_count.orderType = ''          
          break;
        case 'LIKE_COUNT':
          self.parameter.gift_count.orderType = ''
          self.parameter.watch_count_nv.orderType = ''
          self.parameter.duration.orderType = ''
          break;
        case 'GIFT_COUNT':
          self.parameter.duration.orderType = ''
          self.parameter.watch_count_nv.orderType = ''
          self.parameter.like_count.orderType = ''
          break;
        default:
          break;
      }
    },
    changeVisible(bool, desc) {
      this.dialogVisible = bool
      if (desc) {
        this.$emit('toSearch')
      }
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.formInline.dpAccount = this.parameter.dpAccount
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>
